package com.dd.cloud.user.service.paynotice.promode;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 注入回调处理类, 并将bean存放于map
 */
@Component
@Data
@Slf4j
public class NoticeContext {
    private Map<NoticeType, NoticeService> orderHandleMap = new HashMap<>();

    @Autowired
    public void setOrderHandleMap(List<NoticeService> list) {
        // 注入各种类型的回调处理类
        for (NoticeService notice : list) {
            NoticeType annotation = AnnotationUtils.findAnnotation(notice.getClass(), NoticeType.class);
            orderHandleMap.put(annotation, notice);
        }

    }

    public NoticeService getNoticeService(NoticeType noticeType) {
        return orderHandleMap.get(noticeType);
    }
}
